﻿Imports System.Net
Imports System.Text.RegularExpressions
Public Class clsPDFFromLinks
    Private _links As Dictionary(Of String, clsLink)
    Private _pdfLinks As Dictionary(Of String, clsLink)
    Public Sub New(Links As Dictionary(Of String, clsLink))
        _links = Links
        _pdfLinks = New Dictionary(Of String, clsLink)
        _extractPDFLinks()
    End Sub
    Public ReadOnly Property Links As Dictionary(Of String, clsLink)
        Get
            Links = _pdfLinks
        End Get
    End Property
    Public ReadOnly Property Count As Integer
        Get
            Count = _pdfLinks.Count
        End Get
    End Property
    Private Function _pdfNameFromLink(link As String)
        Dim s() As String
        _pdfNameFromLink = ""
        s = Split(link, "/")
        If s.Length > 1 Then
            _pdfNameFromLink = s(s.Length - 1)
        End If
    End Function
    Private Sub _extractPDFLinks()
        Dim link As clsLink
        For Each link In _links.Values
            If link.Url.ToLower.EndsWith(".pdf") Then
                If Not _pdfLinks.ContainsKey(link.Url) Then
                    link.Name = _pdfNameFromLink(link.Url)
                    _pdfLinks.Add(link.Url, link)
                End If
            End If
        Next
    End Sub
End Class
